//
//  FirstTableViewCell.m
//  HappinessTrip
//
//  Created by dllo on 15/10/18.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "FirstTableViewCell.h"
#import "UIImageView+WebCache.h"
#import "Fit.h"

@implementation FirstTableViewCell
-(void)dealloc
{
    [_backImageView release];
    [_leftImageView release];
    [_nameLabel release];
    [_ImageView1 release];
    [_ImageView2 release];
    [_ImageView3 release];
    [_ImageView4 release];
    [_ImageView5 release];
    [_tipsLabel release];
    [_ratingLabel release];
    [_visitLabel release];
    [super dealloc];
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createViews];
    }
    return self;
}
-(void)createViews
{
    _backImageView = [[UIImageView alloc]init];
    [self.contentView addSubview:_backImageView];
    [_backImageView release];
    _leftImageView = [[UIImageView alloc]init];
    [_backImageView addSubview:_leftImageView];
    [_leftImageView release];
    _nameLabel = [[UILabel alloc]init];
    [_backImageView addSubview:_nameLabel];
    [_nameLabel release];
    _ImageView1 = [[UIImageView alloc]init];
    [_backImageView addSubview:_ImageView1];
    [_ImageView1 release];
    _ImageView2 = [[UIImageView alloc]init];
    [_backImageView addSubview:_ImageView2];
    [_ImageView2 release];
    _ImageView3 = [[UIImageView alloc]init];
    [_backImageView addSubview:_ImageView3];
    [_ImageView3 release];
    _ImageView4 = [[UIImageView alloc]init];
    [_backImageView addSubview:_ImageView4];
    [_ImageView4 release];
    _ImageView5 = [[UIImageView alloc]init];
    [_backImageView addSubview:_ImageView5];
    [_ImageView5 release];
    _tipsLabel = [[UILabel alloc]init];
    [_backImageView addSubview:_tipsLabel];
    [_tipsLabel release];
    _ratingLabel = [[UILabel alloc]init];
    [_backImageView addSubview:_ratingLabel];
    [_ratingLabel release];
    _visitLabel = [[UILabel alloc]init];
    [_backImageView addSubview:_visitLabel];
    [_visitLabel release];
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _backImageView.frame = CGRectMake(10 * W, 5 * H, self.contentView.frame.size.width - 20 * W, self.contentView.frame.size.height - 10 * H);
    _leftImageView.frame = CGRectMake(10 * W, 10 * H, 120 * W, 120 * H);
    _nameLabel.frame = CGRectMake(_leftImageView.frame.origin.x + _leftImageView.frame.size.width + 10 * W, _leftImageView.frame.origin.y, _backImageView.frame.size.width - _leftImageView.frame.size.width - 30 * W, 30 * H);
    _ImageView1.frame = CGRectMake(_nameLabel.frame.origin.x, _nameLabel.frame.origin.y + _nameLabel.frame.size.height + 5 * H, 20 * W, 20 * H);
    _ImageView2.frame = CGRectMake(_ImageView1.frame.origin.x + _ImageView1.frame.size.width + 5 * W, _ImageView1.frame.origin.y, _ImageView1.frame.size.width, _ImageView1.frame.size.height);
    _ImageView3.frame = CGRectMake(_ImageView2.frame.origin.x + _ImageView2.frame.size.width + 5 * W, _ImageView1.frame.origin.y, _ImageView1.frame.size.width, _ImageView1.frame.size.height);
    _ImageView4.frame = CGRectMake(_ImageView3.frame.origin.x + _ImageView3.frame.size.width + 5 * W, _ImageView1.frame.origin.y, _ImageView1.frame.size.width, _ImageView1.frame.size.height);
    _ImageView5.frame = CGRectMake(_ImageView4.frame.origin.x + _ImageView4.frame.size.width + 5 * W, _ImageView1.frame.origin.y, _ImageView1.frame.size.width, _ImageView1.frame.size.height);
    _tipsLabel.frame = CGRectMake(_ImageView5.frame.origin.x + _ImageView5.frame.size.width + 10 * W, _ImageView5.frame.origin.y, 80 * W, _ImageView5.frame.size.height);
    _ratingLabel.frame = CGRectMake(_ImageView1.frame.origin.x, _ImageView1.frame.origin.y + _ImageView1.frame.size.height + 5 * H, _nameLabel.frame.size.width, 40 * H);
    _visitLabel.frame = CGRectMake(_ratingLabel.frame.origin.x, _ratingLabel.frame.origin.y + _ratingLabel.frame.size.height + 5 * H, _ratingLabel.frame.size.width, 20 * H);
    
}
-(void)setItem:(FirstItems *)item
{
    if (_item != item) {
        [_item release];
        _item = [item retain];
    }
    _backImageView.layer.cornerRadius = 5;
    _backImageView.layer.masksToBounds = YES;
    [_leftImageView sd_setImageWithURL:[NSURL URLWithString:_item.cover_s]placeholderImage:[UIImage imageNamed:@"dengdai"]];
    _nameLabel.text = _item.name;
    _tipsLabel.text = [NSString stringWithFormat:@"%@ 点评", _item.tips_count];
    _tipsLabel.font = [UIFont systemFontOfSize:13];
    _ratingLabel.text = _item.recommended_reason;
    _ratingLabel.numberOfLines = 0;
    _ratingLabel.font = [UIFont systemFontOfSize:13];
    _visitLabel.text = [NSString stringWithFormat:@"%@ 人去过", _item.visited_count];
    _visitLabel.font = [UIFont systemFontOfSize:13];
    
    if ([_item.rating doubleValue] < 0.5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 0.5 && [_item.rating doubleValue] < 1) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen5"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
        
    }
    if ([_item.rating doubleValue] >= 1 && [_item.rating doubleValue] < 1.5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 1.5 && [_item.rating doubleValue] < 2) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen5"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 2 && [_item.rating doubleValue] < 2.5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 2.5 && [_item.rating doubleValue] < 3) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen5"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 3 && [_item.rating doubleValue] < 3.5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen0"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 3.5 && [_item.rating doubleValue] < 4) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen5"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 4 && [_item.rating doubleValue] < 4.5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen0"];
    }
    if ([_item.rating doubleValue] >= 4.5 && [_item.rating doubleValue] < 5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen5"];
    }
    if ([_item.rating doubleValue] >= 5) {
        _ImageView1.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView2.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView3.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView4.image = [UIImage imageNamed:@"pingfen1"];
        _ImageView5.image = [UIImage imageNamed:@"pingfen1"];
    }
    

}













- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
